{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "from api_key import api_key\n",
    "from openai import OpenAI\n",
    "\n",
    "endpoint = \"https://conductor.arcee.ai/v1\"\n",
    "\n",
    "model = \"virtuoso-large\"\n",
    "\n",
    "client = OpenAI(base_url=endpoint, api_key=api_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Markdown, clear_output, display\n",
    "\n",
    "\n",
    "def print_streaming_response(response):\n",
    "    num_tokens = 0\n",
    "    content = \"\"\n",
    "    for message in response:\n",
    "        if len(message.choices) > 0:\n",
    "            num_tokens += 1\n",
    "            chunk = message.choices[0].delta.content\n",
    "            if chunk:\n",
    "                content += chunk\n",
    "                clear_output(wait=True)\n",
    "                display(Markdown(content))\n",
    "\n",
    "    print(f\"\\n\\nNumber of tokens: {num_tokens}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = client.chat.completions.create(\n",
    "    model=model,\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": \"Write a short horror story in the style of HP Lovecraft. It should take place in the 1920s in Antarctica. Write at least 5000 words.\",\n",
    "        }\n",
    "    ],\n",
    "    temperature=0.9,\n",
    "    stream=True,\n",
    "    max_tokens=16384,\n",
    ")\n",
    "\n",
    "print_streaming_response(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"alice.txt\") as file:\n",
    "    book_text1 = file.read()\n",
    "\n",
    "# Count the number of words\n",
    "num_words = len(book_text1.split())\n",
    "print(f\"Number of words: {num_words}\")\n",
    "\n",
    "response = client.chat.completions.create(\n",
    "    model=model,\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": f\"\"\"Write a psychological profile of the main characters of this book. \n",
    "       Support your analysis with direct relevant quotes from the text.\n",
    "       \n",
    "       Book: {book_text1}\"\"\",\n",
    "        }\n",
    "    ],\n",
    "    temperature=0.9,\n",
    "    stream=True,\n",
    "    max_tokens=2048,\n",
    ")\n",
    "\n",
    "print_streaming_response(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"alice.txt\") as file:\n",
    "    book_text1 = file.read()\n",
    "\n",
    "# Count the number of words\n",
    "num_words = len(book_text1.split())\n",
    "print(f\"Number of words: {num_words}\")\n",
    "\n",
    "with open(\"gatsby.txt\") as file:\n",
    "    book_text2 = file.read()\n",
    "\n",
    "# Count the number of words\n",
    "num_words = len(book_text2.split())\n",
    "print(f\"Number of words: {num_words}\")\n",
    "\n",
    "response = client.chat.completions.create(\n",
    "    model=model,\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": f\"\"\"Draw a parallel between the main characters of these two books.\n",
    "       \n",
    "       First text: {book_text1}\n",
    "       \n",
    "       Second text: {book_text2}\"\"\",\n",
    "        }\n",
    "    ],\n",
    "    temperature=0.9,\n",
    "    stream=True,\n",
    "    max_tokens=2048,\n",
    ")\n",
    "\n",
    "print_streaming_response(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
